package com.example.springboot2.Control;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.concurrent.atomic.AtomicLong;

import com.example.springboot2.CommonHelper.RedisHelper;
import com.example.springboot2.DB_Helper.DataBase;
import com.example.springboot2.DB_Helper.GetConn;
import com.example.springboot2.DB_Helper.JDBCUtils;
import com.example.springboot2.Model.CauseModel;
import com.example.springboot2.Model.MyfirstClass;
import com.example.springboot2.Model.Sys_User;
import com.example.springboot2.Model.TestModel;
import com.example.springboot2.Service.QS_CauseService;
import com.example.springboot2.Service.TestService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/First")
public class FirstController extends BaseController {

    @PostMapping("/test123")
    public  String test()
    {
        String tokken=request.getHeader("token");
        Sys_User user=(Sys_User) redisHelper.get(tokken);
        return  "666";
    }
    @PostMapping("/testclass")
    public MyfirstClass TestClass(@RequestParam()String Name1,@RequestParam() String Name2)
    {
        MyfirstClass temp=new MyfirstClass();
        temp.Name1= Name1;
        temp.Name2= Name2;
        return temp;
    }
    @PostMapping("/sqlTest")
    public List<TestModel> TestSql()
    {
        GetConn conn=new GetConn();
        return conn.getconn();
    }
    @PostMapping("/SearchList")
    public List<TestModel> SearchList()
    {
        TestService service=new TestService();
        return  service.GetList();
    }
    @PostMapping("/SearchCauseList")
    public List<CauseModel> GetCauseList()
    {
        QS_CauseService service=new QS_CauseService();
        return  service.GetList();
    }
    @PostMapping("/TestInsert")
    public  void TestInsert() throws IllegalAccessException {
        TestModel test=new TestModel();
        test.FaultId="123";
        test.Fault="222";
        DataBase<TestModel> dataBase=new DataBase<TestModel>();
        String sql= dataBase.update(test);


        Connection conn = JDBCUtils.findConnection();      //JDBCUtils 自己定义的一个类
        PreparedStatement pre = null;
        ResultSet res = null;
        //String sql = "select * from QS_Cause_FromMESNext";
        try {
            pre = conn.prepareStatement(sql);
            res = pre.executeQuery();

        } catch (SQLException e) {
             e.printStackTrace();
        }
    }
    @Resource
    private RedisHelper redisHelper=new RedisHelper();
    @PostMapping("/TestRedis")
    public  String GetResidsValue()
    {

        redisHelper.set("tokenname","tokenvalue");
        String value=(String) redisHelper.get("tokenname");
        return  value;
    }

}
